package com.book.manager.controller.book;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.book.manager.base.result.Result;
import com.book.manager.dto.*;
import com.book.manager.model.Book;
import com.book.manager.service.BookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: yfan-chen
 * @description:
 * @create: 2021-08-31 22:43
 **/
@RestController
@RequestMapping("/book")
@Api(tags = {"书籍管理"})
public class BookController {
    @Autowired
    private BookService bookService;

    @ApiOperation(value = "查看书籍详情")
    @PostMapping("/getBookDetailWithBookId")
    public Result<Book> getBookDetailWithBookId(@ApiParam(value = "书籍Id") @RequestBody BooKIdReq req) {
        return bookService.getBookDetailWithBookId(req);
    }

    @ApiOperation(value = "分页查询书籍信息")
    @PostMapping("/listBookWithPageKeyMsg")
    public Result<IPage<Book>> listBookWithPageKeyMsg(@ApiParam(value = "页码") @RequestBody PageReq pageReq) {
        return bookService.listBookWithPageKeyMsg(pageReq);
    }

    @ApiOperation(value = "借书")
    @PostMapping("/borrowBookList")
    public Result<BorrowBookResp> borrowBookList(@ApiParam(value = "需要借书的Id") @RequestBody BorrowBookReq borrowBookReq) {
        return bookService.borrowBookList(borrowBookReq);
    }

    @ApiOperation(value = "还书")
    @PostMapping("/backBookList")
    public Result<BorrowBookResp> backBookList(@ApiParam(value = "需要借书的Id") @RequestBody BorrowBookReq borrowBookReq) {
        return bookService.backBookList(borrowBookReq);
    }

    @ApiOperation(value = "当前书籍借出详情")
    @PostMapping("/listBookBorrowDetailWithBookId")
    public Result<List<BookBorrowDetail>> listBookBorrowDetailWithBookId(@ApiParam(value = "需要借书的Id") @RequestBody BooKIdReq req) {
        return bookService.listBookBorrowDetailWithBookId(req);
    }

    @ApiOperation(value = "本人所借出图书详情")
    @PostMapping("/listBookBorrowDetailWithMe")
    public Result<List<BookBorrowDetail>> listBookBorrowDetailWithMe() {
        return bookService.listBookBorrowDetailWithMe();
    }
}
